package se.liu.oschi129.world.model;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;

import se.liu.oschi129.animation.Animation;

/**
 * This class gives WorldObjects an abstract way to access drawing methods.
 * 
 * @author oschi129
 */
public class WorldGraphics {

	private Graphics2D g2d;
	
	/**
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 * - - - - - - - - - - - - Constructors - - - - - - - - - - - 
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 */
	
	public WorldGraphics(Graphics2D g2d) {
		this.g2d = g2d;
	}
	
	/**
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 * - - - - - - - - - - - Public methods - - - - - - - - - - 
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 */
	
	/** Sets the font used for drawing */
	public void setFont(Font font) {
		g2d.setFont(font);
	}
	
	/** Sets the color used for drawing */
	public void setColor(Color color) {
		g2d.setColor(color);
	}
	
	/** Sets the alpha composite used for drawing */
	public void setAlpha(double alpha) {
		g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) alpha));
	}
	
	/** Draws an animation in the world */
	public void drawAnimation(double x, double y, Animation animation) {
		drawAnimation(x, y, animation, 0);
	}
	
	/** Draws an animation in the world */
	public void drawAnimation(double x, double y, Animation animation, int subimage) {
		g2d.drawImage(animation.subimage(subimage), (int) x, (int) y, null);
	}

	/** Draws an animation in the world */
	public void drawAnimation(double x, double y, double width, double height, Animation animation) {
		drawAnimation(x,y,width,height,animation,0);
	}
	
	/** Draws an animation in the world */
	public void drawAnimation(double x, double y, double width, double height, Animation animation, int subimage) {
		g2d.drawImage(animation.subimage(subimage), (int) x, (int) y, (int) width, (int) height, null);
	}
	
	/** Draws a text in the world */
	public void drawText(double x, double y, String str) {
		g2d.drawString(str , (int) x, (int) y);
	}
	
	/** Draws a rectangle in the world */
	public void fillRect(double x, double y, double width, double height) {
		g2d.fillRect((int) x, (int) y, (int) width, (int) height);
	}
	
}
